const express = require('express')
const logger = require('morgan')
const cors = require('cors')
const session = require('express-session')

const app = express()
const port = 3000
const host = '192.168.31.197'
// 开发插件
app.use(logger('dev'))


app.use(cors())
// cookie和session
app.use(session({
  resave: false,
  saveUninitialized: true,
  secret: ['expressServer'],
  name: 'yuanshuo',
  cookie: {
    maxAge: 1000 * 60 * 60 * 12
  }
}))


// post解析
app.use(express.json());
app.use(express.urlencoded({ extended: false }))

// 静态目录
app.use(express.static('assets',{maxAge: 1000*60*60*12}))

// 路由处理
app.use(require('./router/pageRouter'))
app.use(require('./router/apiRouter'))


// 错误处理
app.use(require('./router/errorRouter').errorRouter)
app.use(require('./router/errorRouter').errorHandler)


app.listen(port,() => {
  console.log(`Example app listening at http://localhost:${port}`)
})